/*
 * Puerta.h
 *
 */

#ifndef PUERTA_H_
#define PUERTA_H_

#include "API/APICommon.h"
#include "API/Persona.h"
#include "IPC/SharedMemory2.h"
#include "IPC/Semaphore.h"
#include "Middleware/MiddlewareMessages.h"
#include "IPC/MessageQueue2.h"

namespace API{
class Puerta
{
public:
typedef enum {IN_DOOR=0, OUT_DOOR, CLIENT} doorTypeEnum;

public:
	/**
	 *
	 */
	Puerta(doorTypeEnum doorType);

	/**
	 *
	 */
	virtual ~Puerta();

	/**
	 *
	 */
	void init();

	/**
	 *
	 */
	void destroy();

	/**
	 *
	 */
	bool entrarParque(PuertaId nPuerta,Persona &persona, int &error);

	/**
	 *
	 */
	void salirParque(PuertaId nPuerta,Persona &persona, int &error);

	/**
	 *
	 */
	void run(PuertaId nPuerta);
private:
	MessageQueue2<entryParkRequest> * m_entryRequestQueue;
	MessageQueue2<entryParkReply>   * m_entryReplyQueue;
	MessageQueue2<exitParkRequest>  * m_exitRequestQueue;
	MessageQueue2<exitParkReply>    * m_exitReplyQueue;

	Semaphore m_semaphore;
	SharedMemory2<int> m_capacity;
	doorTypeEnum m_doorType;


	bool m_doRun;
};

}//end namespace API

#endif /* PUERTA_H_ */
